<template>
	<view class="register form">
		<view class="ipt-group">
			<image class="icon" src="../../static/images/ac1.png" mode="aspectFit"></image>
			<input class="ipt" type="text" value="" placeholder="请输入账号" placeholder-class="ipt-pc" v-model="form.account">
		</view>
		<view class="ipt-group">
			<image class="icon" src="../../static/images/ac2.png" mode="aspectFit"></image>
			<input class="ipt" type="password" value="" placeholder="请输入密码" placeholder-class="ipt-pc" v-model="form.password">
		</view>
		<view class="ipt-group">
			<image class="icon" src="../../static/images/ac3.png" mode="aspectFit"></image>
			<input class="ipt" type="number" password maxlength="6" value="" placeholder="请输入交易密码" placeholder-class="ipt-pc" v-model="form.trade_password">
		</view>
		<view class="ipt-group">
			<image class="icon" src="../../static/images/ac4.png" mode="aspectFit"></image>
			<input class="ipt" type="text" value="" placeholder="请输入邀请码" placeholder-class="ipt-pc" v-model="form.invite_code">
		</view>
		
		<view class="btn-wrap">
			<button class="cu-btn block radius register" @click="check">
				注册
			</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					account: '',
					password: '',
					trade_password: '',
					invite_code: ''
				}
			};
		},
		methods: {
			check() {
				let permit = +/^\d{6}$/.test(this.form.trade_password)
				if (permit) {
					this.register();
				} else {
					uni.showToast({
						title: '交易密码必须为6位纯数字',
						icon: 'none'
					})
				}
			},
			register() {
				this.$u.post('/passport/register', this.form).then(res => {
					if (res.data.success) {
						uni.showToast({
							title: '注册成功',
							icon: 'none'
						})
						uni.navigateTo({
							url: '/pages/account/step1?token=' + res.data.result.token
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	
</style>
